package com.bocai.yuweiwangluo.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.TextUtils;

import com.bocai.yuweiwangluo.R;
import com.bocai.yuweiwangluo.base.BaseActivity;
import com.bocai.yuweiwangluo.event.MainEvent;
import com.bocai.yuweiwangluo.utils.GetLocationInfo_BD;
import com.bocai.yuweiwangluo.utils.MyConst;
import com.bocai.yuweiwangluo.utils.SharePrefencesUtil;

public class SplashActivity extends BaseActivity {
	private SharedPreferences preferences;

	@Override
	protected int contentView() {
		return R.layout.activity_splash;
	}

	@Override
	protected void setData() {
		GetLocationInfo_BD.initLocation(this);
//		new Handler().postDelayed(new Runnable() {
//			@Override
//			public void run() {
//				jumpToLogin();
//			}
//		},3000);
	}

	@Override
	public void onEventMainThread(MainEvent event) {
		super.onEventMainThread(event);
		if(event.msg.equals("location"))
		{
			jumpToLogin();
		}
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		MyConst.setIslunched(false);
	}

	public void jumpToLogin() {
		preferences = getSharedPreferences("count",MODE_APPEND);
		int count = preferences.getInt("count", 0);

		//判断程序与第几次运行，如果是第一次运行则跳转到引导页面
		if (count == 0) {
			Intent intent = new Intent();
			intent.setClass(getApplicationContext(),GuideActivity.class);
			startActivity(intent);
			this.finish();
		}else {
			// 跳转到登录页(设置自动登录)
//			SharedPreferences preferences=getSharedPreferences("user", MODE_PRIVATE);
//			String user_id=preferences.getString("user_id","");
			if(TextUtils.isEmpty(SharePrefencesUtil.getUser_id(this))){
				Intent i = new Intent(SplashActivity.this, LoginActivity.class);
				startActivity(i);
				MyConst.setIslunched(false);
				finish();
			}else{
				MyConst.user_id=SharePrefencesUtil.getUser_id(this);
				Intent i = new Intent(SplashActivity.this, HomeActivity.class);
				startActivity(i);
				MyConst.setIslunched(false);
				finish();

			}

		}
		Editor editor = preferences.edit();
		//存入数据
		editor.putInt("count", ++count);
		//提交修改
		editor.commit();
		}

}
